﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace InventoryManager
{
    public partial class AddProductForm : Form
    {
        public string productName;
        public string productDimension;

        public AddProductForm(ComboBox comBoBox)
        {
            InitializeComponent();
            foreach (string productName in comBoBox.Items)
                ProductComboBox.Items.Add(productName);

            ProductComboBox.SelectedIndex = 0;
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            if (DimensionTextBox.Text == "" || (NameTextBox.Text == "" && NewProductNameRadioButton.Checked)
                || ProductComboBox.SelectedIndex == -1 && ExistingProductNameRadioButton.Checked)
            {
                if (DimensionTextBox.Text == "")
                    DimensionTextBox.BackColor = Color.Red;
                if (NameTextBox.Text == "" && NewProductNameRadioButton.Checked)
                    NameTextBox.BackColor = Color.Red;
                if (ProductComboBox.SelectedIndex == -1 && ExistingProductNameRadioButton.Checked)
                    ProductComboBox.BackColor = Color.Red;
            }
            else
            {
                if (ExistingProductNameRadioButton.Checked)
                    productName = ProductComboBox.Items[ProductComboBox.SelectedIndex].ToString();
                else
                    productName = NameTextBox.Text;

                productDimension = DimensionTextBox.Text;
                this.DialogResult = DialogResult.OK;
            }
        }

        private void DimensionTextBox_TextChanged(object sender, EventArgs e)
        {
            DimensionTextBox.BackColor = Color.White;
        }

        private void NameTextBox_TextChanged(object sender, EventArgs e)
        {
            NameTextBox.BackColor = Color.White;
        }

        private void NewProductNameRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            ProductComboBox.Enabled = ExistingProductNameRadioButton.Checked;
            DimensionTextBox.BackColor = Color.White;
            NameTextBox.BackColor = Color.White;
        }

        private void ExistingProductNameRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            NameTextBox.Enabled = NewProductNameRadioButton.Checked;
            DimensionTextBox.BackColor = Color.White;
            NameTextBox.BackColor = Color.White;
        }
    }
}
